package com.oitsm.sys.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/**
 * 菜单类
 * @author Arab Runner
 * Jun 18, 2011 2:46:10 PM
 */
@Entity
@Table(name="menu")
public class Menu implements Serializable{
	private static final long serialVersionUID = -7037349300457067680L;
	
	public static final int TYPE_ITEM = 0;
	public static final int TYPE_MENU = 1;
	public static final int TYPE_GROUP = 2;
	
	@Id
	private Long id;
	/**
	 * ���
	 */
	@Column(name="name")   
	private String name;
	/**
	 * ����
	 */
	@Column(name="desc")   
	private String desc;
	/**
	 * ��id
	 */
	@Column(name="parentid")   
	private Long parentId;
	/**
	 * js·��
	 */
	@Column(name="jspaths")   
	private String jsPaths;
	/**
	 * �齨����
	 */
	@Column(name="componentname")   
	private String componentName;
	/**
	 * icon
	 */
	@Column(name="icon")   
	private String icon;
	/**
	 * ����
	 */
	@Column(name="order")   
	private Integer order;
	/**
	 * ����
	 */
	@Column(name="level")   
	private Integer level;
	/**
	 * ����
	 */
	@Column(name="type")   
	private Integer type;
	
	@javax.persistence.Transient
	private List<Menu> children = new ArrayList<Menu>();
	
	public List<Menu> getChildren() {
		return children;
	}

	public void addChild(Menu child){
		children.add(child);
	}
	
	public Menu(){}

	public Menu(Long id, String name, String desc, Long parentId,
			String jsPaths, String componentName, String icon, Integer order,
			Integer level, Integer type) {
		super();
		this.id = id;
		this.name = name;
		this.desc = desc;
		this.parentId = parentId;
		this.jsPaths = jsPaths;
		this.componentName = componentName;
		this.icon = icon;
		this.order = order;
		this.level = level;
		this.type = type;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	public String getJsPaths() {
		return jsPaths;
	}

	public void setJsPaths(String jsPaths) {
		this.jsPaths = jsPaths;
	}

	public String getComponentName() {
		return componentName;
	}

	public void setComponentName(String componentName) {
		this.componentName = componentName;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public Integer getOrder() {
		return order;
	}

	public void setOrder(Integer order) {
		this.order = order;
	}

	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public void setChildren(List<Menu> children) {
		this.children = children;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((componentName == null) ? 0 : componentName.hashCode());
		result = prime * result + ((desc == null) ? 0 : desc.hashCode());
		result = prime * result + ((icon == null) ? 0 : icon.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((jsPaths == null) ? 0 : jsPaths.hashCode());
		result = prime * result + ((level == null) ? 0 : level.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((order == null) ? 0 : order.hashCode());
		result = prime * result
				+ ((parentId == null) ? 0 : parentId.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Menu other = (Menu) obj;
		if (componentName == null) {
			if (other.componentName != null)
				return false;
		} else if (!componentName.equals(other.componentName))
			return false;
		if (desc == null) {
			if (other.desc != null)
				return false;
		} else if (!desc.equals(other.desc))
			return false;
		if (icon == null) {
			if (other.icon != null)
				return false;
		} else if (!icon.equals(other.icon))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (jsPaths == null) {
			if (other.jsPaths != null)
				return false;
		} else if (!jsPaths.equals(other.jsPaths))
			return false;
		if (level == null) {
			if (other.level != null)
				return false;
		} else if (!level.equals(other.level))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (order == null) {
			if (other.order != null)
				return false;
		} else if (!order.equals(other.order))
			return false;
		if (parentId == null) {
			if (other.parentId != null)
				return false;
		} else if (!parentId.equals(other.parentId))
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}
}
